/**
 * Created by aaronjin on 16/11/24.
 */

const webpack = require('webpack');
const autoprefixer = require('autoprefixer-core');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const resolve = require('path').resolve;
const css = require('./css.js');

module.exports = function (env) {
    try {
        var loaders=[
            {
                test: /\.(js|jsx)?$/,
                exclude: /node_modules/,
                loaders: ['babel-loader']
            },{
                test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot|ico)$/,
                loader: 'file-loader?name='+env.project+'/[path][name].[ext]'
            },{
                test: /\.html$/,
                loader: 'html-loader'
            },{
                test: /\.css$/,
                loader: ExtractTextPlugin.extract({ fallbackLoader: 'style-loader', loader: 'css?sourceMap!postcss' })
            },
            {
                test: /\.scss$/,
                loader: css.extractSASS.extract({ fallbackLoader: 'style-loader', loader: [
                    "css-loader",
                    "autoprefixer-loader?browsers=last 20 version",
                    "sass-loader?outputStyle=expanded"
                ].join("!") })
            },
            {
                test: /\.less$/,
                loader: css.extractLESS.extract({ fallbackLoader: 'style-loader', loader: [
                    "css-loader",
                    "autoprefixer-loader?browsers=last 20 version",
                    "less-loader"
                ].join("!") })
            }
        ];

        return loaders;
    } catch (e) {
        throw new Error(e);
    }

};

